#include "Apprentice.h"
#include "ApprenticeOwnedStates.h"
//Like Apprentice.h, this file is to be moderated by Strog
//If you want to commit, ask me first pretty please

//Apprentice::Apprentice(int id):BaseGameEntity(id),
//						m_Location(Treetops),
//						m_iComfort(0),
//						m_iThirst(0),
//						m_iFatigue(0),
//						m_pCurrentState(VisitTreetopsAndSleep::Instance())  //as of now, this state doesn't exist and needs to be created
//
//{}

void Apprentice::ChangeState(State<Apprentice>* pNewState)
{
	//verifies that both states are valid before attempting to call methods
	assert(pCurrentState && pNewState);

	//call exit method of the current state before leaving it
	pCurrentState->Exit(this);

	//change to new state
	pCurrentState = pNewState;

	//call enter method of new state
	pCurrentState->Enter(this);
}

bool Apprentice::Thirsty()
{
	if(iThirst > ciaThirstFlag)
		return true;

	return false;
}


bool Apprentice::Hungry()
{
	if(iHunger > ciaHungerFlag)
		return true;
	
	return false;
}

bool Apprentice::Fatigued()
{
	if(iFatigue > ciaTiredFlag)
		return true;

	return false;
}

bool Apprentice::Uncomfortable()
{
	if(iDiscomfort > ciaDiscomfortFlag)
		return true;

	return false;
}

void Apprentice::Update()
{
	//Takes away one tick from the hunted timer.
	HuntedItterator();

	//this is where the code will be that determines what the apprentice does
	//aka if(Thirsty()) then change state

	if(pStateMachine->CurrentState())
	{
		pStateMachine->CurrentState()->Execute(this);
	}
}

void Apprentice::FindActivity()
{
	if(Thirsty())
	{
		pStateMachine->ChangeState(VisitOasisAndDrinkApp::Instance());
	}
	else if(Hungry())
	{
		pStateMachine->ChangeState(VisitJungleAndHunt::Instance());
	}
	else if(Fatigued())
	{
		pStateMachine->ChangeState(VisitTreetopsAndSleep::Instance());
	}
	else if(Uncomfortable())
	{
		pStateMachine->ChangeState(VisitOasisAndBask::Instance());
	}
	else
	{
	 pStateMachine->ChangeState(VisitTreetopsAndPlay::Instance());
	}
}



//void Apprentice::FindActivity()
//{
//	int need = 10;	   //checks highest need
//	int needPoint; //points to needed stat
//	bool check[4] = {false}; //Temp used to check flags
//	int check2[4] = {0}; //Temp used to check flags
//
//	if(iThirst > ciaThirstFlag)
//	{check[0] = true;check2[0] = iThirst;}
//	if(iHunger > ciaHungerFlag)
//	{check[1] = true;check2[1] = iHunger;}
//		
//	if(iFatigue > ciaTiredFlag)
//	{check[2] = true;check2[2] = iFatigue;}
//	if(iDiscomfort > ciaDiscomfortFlag)
//	{check[3] = true;check2[3] = iDiscomfort;}
//
//	for(int i = 0; i < 4 ; ++i)
//	{
//		if(check[i] = true&&check2[i] < need)
//		{
//			need = check2[i];
//			needPoint = i;
//		}
//	}
//
//	switch(needPoint)
//	{
//	case 0: pStateMachine->ChangeState(VisitOasisAndDrinkApp::Instance());
//		break;
//	case 1: pStateMachine->ChangeState(VisitJungleAndHunt::Instance());
//		break;
//	case 2: pStateMachine->ChangeState(VisitTreetopsAndSleep::Instance());
//		break;
//	case 3: pStateMachine->ChangeState(VisitOasisAndBask::Instance());
//		break;
//	default: pStateMachine->ChangeState(VisitTreetopsAndPlay::Instance());
//	}
//}